package com.ruoyi.slip.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slip.domain.SalarySlipVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slip.domain.SalarySlip;
import com.ruoyi.slip.service.ISalarySlipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工工资条明细Controller
 * 
 * @author cxs
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/slip/slip")
public class SalarySlipController extends BaseController
{
    @Autowired
    private ISalarySlipService salarySlipService;

    /**
     * 查询员工工资条明细列表
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalarySlipVO salarySlipvo)
    {
        startPage();
        List<SalarySlipVO> list = salarySlipService.selectSalarySlipList(salarySlipvo);
        return getDataTable(list);
    }

    /**
     * 导出员工工资条明细列表
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:export')")
    @Log(title = "员工工资条明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalarySlip salarySlip)
    {
//        List<SalarySlip> list = salarySlipService.selectSalarySlipList(salarySlip);
        ExcelUtil<SalarySlip> util = new ExcelUtil<SalarySlip>(SalarySlip.class);
//        util.exportExcel(response, list, "员工工资条明细数据");
    }

    /**
     * 获取员工工资条明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salarySlipService.selectSalarySlipById(id));
    }

    /**
     * 新增员工工资条明细
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:add')")
    @Log(title = "员工工资条明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalarySlip salarySlip)
    {
        return toAjax(salarySlipService.insertSalarySlip(salarySlip));
    }

    /**
     * 修改员工工资条明细
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:edit')")
    @Log(title = "员工工资条明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalarySlip salarySlip)
    {
        return toAjax(salarySlipService.updateSalarySlip(salarySlip));
    }

    /**
     * 删除员工工资条明细
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:remove')")
    @Log(title = "员工工资条明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salarySlipService.deleteSalarySlipByIds(ids));
    }


    /**
     * 核算薪资
     */
    @PreAuthorize("@ss.hasPermi('slip:slip:calculate')")
    @Log(title = "员工工资条明细", businessType = BusinessType.UPDATE)
    @PutMapping("/calculate/{ids}")
    public AjaxResult calculate(@PathVariable List<Long> ids)
    {
        return toAjax(salarySlipService.calculateSalary(ids));
    }
}
